package com.itheima.exerciseTest.test60_69;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class Test62 {
    public static void main(String[] args) throws InterruptedException {
        // 创建线程池对象
        ExecutorService executorService = Executors.newCachedThreadPool();

        // submit() 添加任务
        executorService.submit(new Thread(){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + " 正在执行");
            }
        });

        Thread.sleep(5);

        executorService.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + " 正在执行");
            }
        });

        Thread.sleep(5);

        executorService.submit(new FutureTask<String>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println(Thread.currentThread().getName() + " 正在执行");
                return null;
            }
        }) {
        });

        // 关闭池
        executorService.shutdown();
    }
}
